/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * PainelBatalha.java
 *
 * Created on 21/11/2011, 20:36:32
 */
package projetointegrado;

import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.Graphics;
import java.awt.Image;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JPanel;


/**
 *
 * @author Thor
 */
public class PainelBatalha extends javax.swing.JPanel {
    Player player;
    Enemy inimigo;
    String hpInimigo, hpPlayer;
    InterfaceBatalha interfaceBatalha;
    boolean pintado = false;
  //  Materia materiaMitica = new Materia();
    DesenhaTela dt;
    /** Creates new form PainelBatalha */
      public void paintComponent(Graphics g) {
        Image imagem = new ImageIcon("src/Imagens/bg_battle.jpg").getImage();
        g.drawImage(imagem, 0, 0, this);
        if(pintado == false){
        repaint();
        pintado = true;
        }
    }
    public  PainelBatalha(Player player, Enemy inimigo, DesenhaTela dt) {
       // Container container = frame.getContentPane();
        ProjetoIntegrado.sound.playBattle();
        Flag.andar1BlocoE = false;
        JPanel painelImagemInimigo = new JPanel();
        painelImagemInimigo.setBounds(500,120,208,189);
        painelImagemInimigo.setOpaque(false);
        this.add(painelImagemInimigo);
        
        this.player = player;
        this.inimigo = inimigo;
        this.dt = dt;
        //dt.jj.add(this);
       // Flag.andar1BlocoE = false;
        System.out.println(player.getHpAtual());
        System.out.println(inimigo.getHp());
        interfaceBatalha = new InterfaceBatalha();
        //inimigo.setMateriaDoInimigo(player.tecnologiaSociedade);
        
        initComponents();
        if(inimigo.materia.getTipo().equals("Humanas")){
            interfaceBatalha.ataqueHum();
            ImageIcon imagemInimigo = new ImageIcon("src/Imagens/necronomicon.png");
            JLabel enemyPicture = new JLabel(imagemInimigo);
            painelImagemInimigo.add(enemyPicture);
            jLabel4.setText("A wilid SEMINARIO has appeared!");
        }else if(inimigo.materia.getTipo().equals("Matematica")){
            interfaceBatalha.ataqueMat();
            ImageIcon imagemInimigo = new ImageIcon("src/Imagens/cereal.png");
            JLabel enemyPicture = new JLabel(imagemInimigo);
            painelImagemInimigo.add(enemyPicture);
            jLabel4.setText("A wild EXERCICIO MACABRO has appeared!");
        }else if(inimigo.materia.getTipo().equals("Gestao")){
            interfaceBatalha.ataqueAdm();
            ImageIcon imagemInimigo = new ImageIcon("src/Imagens/quite.png");
            JLabel enemyPicture = new JLabel(imagemInimigo);
            painelImagemInimigo.add(enemyPicture);
            jLabel4.setText("A wild ESTUDO DE CASO has appeared!");
        }else if(inimigo.materia.getTipo().equals("Informatica")){
            interfaceBatalha.ataqueProg();
            ImageIcon imagemInimigo = new ImageIcon("src/Imagens/troll.png");
            JLabel enemyPicture = new JLabel(imagemInimigo);
            painelImagemInimigo.add(enemyPicture);
            jLabel4.setText("A wild LISTA DE EXERCICIOS has appeared!");
        }

    }


    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        painelVidaInimigo = new javax.swing.JPanel();
        painelVidaPlayer = new javax.swing.JPanel();
        labelAtaqueProgPlayer = new javax.swing.JLabel();
        labelAtaqueMatPlayer = new javax.swing.JLabel();
        labelAtaqueHumPlayer = new javax.swing.JLabel();
        labelAtaqueAdmPlayer = new javax.swing.JLabel();
        labelVidaInimigo = new javax.swing.JLabel();
        labelVidaPlayer = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();

        setPreferredSize(new java.awt.Dimension(830, 600));
        setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        painelVidaInimigo.setBackground(new java.awt.Color(255, 0, 0));

        javax.swing.GroupLayout painelVidaInimigoLayout = new javax.swing.GroupLayout(painelVidaInimigo);
        painelVidaInimigo.setLayout(painelVidaInimigoLayout);
        painelVidaInimigoLayout.setHorizontalGroup(
            painelVidaInimigoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 280, Short.MAX_VALUE)
        );
        painelVidaInimigoLayout.setVerticalGroup(
            painelVidaInimigoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 12, Short.MAX_VALUE)
        );

        add(painelVidaInimigo, new org.netbeans.lib.awtextra.AbsoluteConstraints(110, 125, 280, -1));

        painelVidaPlayer.setBackground(new java.awt.Color(0, 204, 0));

        javax.swing.GroupLayout painelVidaPlayerLayout = new javax.swing.GroupLayout(painelVidaPlayer);
        painelVidaPlayer.setLayout(painelVidaPlayerLayout);
        painelVidaPlayerLayout.setHorizontalGroup(
            painelVidaPlayerLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 280, Short.MAX_VALUE)
        );
        painelVidaPlayerLayout.setVerticalGroup(
            painelVidaPlayerLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 10, Short.MAX_VALUE)
        );

        add(painelVidaPlayer, new org.netbeans.lib.awtextra.AbsoluteConstraints(480, 405, 280, 10));

        labelAtaqueProgPlayer.setFont(new java.awt.Font("Californian FB", 1, 18));
        labelAtaqueProgPlayer.setText("Informatizar!");
        labelAtaqueProgPlayer.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                labelAtaqueProgPlayerMouseClicked(evt);
            }
        });
        add(labelAtaqueProgPlayer, new org.netbeans.lib.awtextra.AbsoluteConstraints(640, 500, 110, 30));

        labelAtaqueMatPlayer.setFont(new java.awt.Font("Californian FB", 1, 18));
        labelAtaqueMatPlayer.setText("Matematicar!");
        labelAtaqueMatPlayer.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                labelAtaqueMatPlayerMouseClicked(evt);
            }
        });
        add(labelAtaqueMatPlayer, new org.netbeans.lib.awtextra.AbsoluteConstraints(490, 500, 130, 30));

        labelAtaqueHumPlayer.setFont(new java.awt.Font("Californian FB", 1, 18));
        labelAtaqueHumPlayer.setText("Humanizar!");
        labelAtaqueHumPlayer.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                labelAtaqueHumPlayerMouseClicked(evt);
            }
        });
        add(labelAtaqueHumPlayer, new org.netbeans.lib.awtextra.AbsoluteConstraints(640, 540, 120, 30));

        labelAtaqueAdmPlayer.setFont(new java.awt.Font("Californian FB", 1, 18));
        labelAtaqueAdmPlayer.setText("Gerir!");
        labelAtaqueAdmPlayer.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                labelAtaqueAdmPlayerMouseClicked(evt);
            }
        });
        add(labelAtaqueAdmPlayer, new org.netbeans.lib.awtextra.AbsoluteConstraints(490, 540, 130, 30));

        labelVidaInimigo.setFont(new java.awt.Font("Millennia", 0, 14));
        labelVidaInimigo.setText(Integer.toString(inimigo.getHp()));
        add(labelVidaInimigo, new org.netbeans.lib.awtextra.AbsoluteConstraints(110, 140, -1, -1));

        labelVidaPlayer.setFont(new java.awt.Font("Millennia", 0, 14));
        labelVidaPlayer.setText(Integer.toString(player.getHpAtual()));
        add(labelVidaPlayer, new org.netbeans.lib.awtextra.AbsoluteConstraints(480, 420, -1, -1));

        jLabel1.setFont(new java.awt.Font("Millennia", 0, 14));
        jLabel1.setText("/"+Integer.toString(player.getHp()));
        add(jLabel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(510, 420, -1, -1));

        jLabel2.setFont(new java.awt.Font("Millennia", 0, 14));
        jLabel2.setText(player.nome);
        add(jLabel2, new org.netbeans.lib.awtextra.AbsoluteConstraints(480, 390, -1, -1));

        jLabel3.setFont(new java.awt.Font("Millennia", 0, 14));
        jLabel3.setText(inimigo.getMateria().getDescricao());
        add(jLabel3, new org.netbeans.lib.awtextra.AbsoluteConstraints(110, 105, -1, -1));

        jLabel4.setFont(new java.awt.Font("Tahoma", 3, 12)); // NOI18N
        jLabel4.setText("jLabel4");
        add(jLabel4, new org.netbeans.lib.awtextra.AbsoluteConstraints(40, 480, 360, 40));
    }// </editor-fold>//GEN-END:initComponents

private void labelAtaqueMatPlayerMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_labelAtaqueMatPlayerMouseClicked
    if(inimigo.materia.getTipo().equals("Matematica")){
        int i = (int)(Math.random()*player.frasesBatalhaMat.size());
        jLabel4.setText(player.frasesBatalhaMat.get(i));
    
    inimigo = interfaceBatalha.danoAoInimigoMat(player, inimigo);
    
    labelVidaInimigo.setText(Integer.toString(inimigo.getHp()));
    if(inimigo.getHp() <= 0){
    //    acordaThread();
        
        ProjetoIntegrado.sound.stopMidi();
        inimigo.setHp(100);
        player.setSkillMat(player.getSkillMat()+3);
        ProjetoIntegrado.pld.setSkillMat(player.getSkillMat());
        Flag.andar1BlocoE = false;
        Flag.andar2BlocoE = false;
        Flag.andar3BlocoE = false;
        Flag.playSoundOnce = true;
        this.setVisible(false);
        dt.jj.setVisible(true);
        dt.jj.requestFocus();
        inimigo.getMateria().setFeitaNoDia(true);
        inimigo.getMateria().setFeitaNaSemana(inimigo.getMateria().getFeitaNaSemana()+1);
        inimigo.getMateria().setContadorCargaFeita(inimigo.getMateria().getContadorCargaFeita()+30);
        if(inimigo.getMateria().getContadorCargaFeita() == inimigo.getMateria().getCargaHoraria()){
            inimigo.getMateria().setStatus(3);
            
        }
    }
    /*IMPLEMENTAR NA CLASSE DESENHATELA METODO DE ATUALIZAR DADOS DO PLAYER
    if(inimigo.getHp() == 0){
     * DesenhaTela.atualizaDadosPlayer(player)
     * this.dispose();
     * }
     */
    player = interfaceBatalha.danoAoPlayer(player, inimigo);
   
    labelVidaPlayer.setText(Integer.toString(player.getHpAtual())); 
    if(player.getHpAtual() <= 0){
        ProjetoIntegrado.sound.stopMidi();
        ProjetoIntegrado.sound.playGameOver();
        this.setVisible(false);
        ProjetoIntegrado.pgo.setVisible(true);
    }
    }else {
        jLabel4.setText("Nao foi nada efetivo!");
        player = interfaceBatalha.danoAoPlayer(player, inimigo);
        labelVidaPlayer.setText(Integer.toString(player.getHpAtual()));
        if(player.getHpAtual() <= 0){
        ProjetoIntegrado.sound.stopMidi();
        ProjetoIntegrado.sound.playGameOver();
        this.setVisible(false);
        ProjetoIntegrado.pgo.setVisible(true);
    }
    }    
}//GEN-LAST:event_labelAtaqueMatPlayerMouseClicked

private void labelAtaqueProgPlayerMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_labelAtaqueProgPlayerMouseClicked
    if(inimigo.materia.getTipo().equals("Informatica")){
        int i = (int)(Math.random()*player.frasesBatalhaProg.size());
        jLabel4.setText(player.frasesBatalhaProg.get(i));
    
    inimigo = interfaceBatalha.danoAoInimigoProg(player, inimigo);
    labelVidaInimigo.setText(Integer.toString(inimigo.getHp()));
    /*IMPLEMENTAR NA CLASSE DESENHATELA METODO DE ATUALIZAR DADOS DO PLAYER
    if(inimigo.getHp() == 0){
     * DesenhaTela.atualizaDadosPlayer(player)
     * this.dispose();
     * }
     */
    if(inimigo.getHp() <= 0){
    //    acordaThread();
        ProjetoIntegrado.sound.stopMidi();
        inimigo.setHp(100);
        player.setSkillProg(player.getSkillProg()+3);
        ProjetoIntegrado.pld.setSkillProg(player.getSkillProg());
        Flag.andar1BlocoE = false;
         Flag.andar2BlocoE = false;
        Flag.andar3BlocoE = false;
        Flag.playSoundOnce = true;
        this.setVisible(false);
        dt.jj.setVisible(true);
        dt.jj.requestFocus();
        inimigo.getMateria().setFeitaNoDia(true);
        inimigo.getMateria().setFeitaNaSemana(inimigo.getMateria().getFeitaNaSemana()+1);
        inimigo.getMateria().setContadorCargaFeita(inimigo.getMateria().getContadorCargaFeita()+30);
        if(inimigo.getMateria().getContadorCargaFeita() == inimigo.getMateria().getCargaHoraria()){
            inimigo.getMateria().setStatus(3);
            
            
        }
    }
    player = interfaceBatalha.danoAoPlayer(player, inimigo);
    labelVidaPlayer.setText(Integer.toString(player.getHpAtual()));
    if(player.getHpAtual() <= 0){
        ProjetoIntegrado.sound.stopMidi();
        ProjetoIntegrado.sound.playGameOver();
        this.setVisible(false);
        ProjetoIntegrado.pgo.setVisible(true);
    }
    }else{
        jLabel4.setText("Nao foi nada efetivo!");
        player = interfaceBatalha.danoAoPlayer(player, inimigo);
        labelVidaPlayer.setText(Integer.toString(player.getHpAtual()));
        if(player.getHpAtual() <= 0){
        ProjetoIntegrado.sound.stopMidi();
        ProjetoIntegrado.sound.playGameOver();
        this.setVisible(false);
        ProjetoIntegrado.pgo.setVisible(true);
        
    }
    }
}//GEN-LAST:event_labelAtaqueProgPlayerMouseClicked

private void labelAtaqueAdmPlayerMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_labelAtaqueAdmPlayerMouseClicked
    if(inimigo.materia.getTipo().equals("Gestao")){
        int i = (int)(Math.random()*player.frasesBatalhaAdm.size());
        jLabel4.setText(player.frasesBatalhaAdm.get(i));
   
    inimigo = interfaceBatalha.danoAoInimigoAdm(player, inimigo);
    labelVidaInimigo.setText(Integer.toString(inimigo.getHp()));
    /*IMPLEMENTAR NA CLASSE DESENHATELA METODO DE ATUALIZAR DADOS DO PLAYER
    if(inimigo.getHp() == 0){
     * DesenhaTela.atualizaDadosPlayer(player)
     * this.dispose();
     * }
     */ 
    if(inimigo.getHp() <= 0){
    //    acordaThread();
        ProjetoIntegrado.sound.stopMidi();
        inimigo.setHp(100);
        player.setSkillAdm(player.getSkillAdm()+3);
        ProjetoIntegrado.pld.setSkillAdm(player.getSkillAdm());
        Flag.andar1BlocoE = false;
         Flag.andar2BlocoE = false;
        Flag.andar3BlocoE = false;
        Flag.playSoundOnce = true;
        this.setVisible(false);
        dt.jj.setVisible(true);
        dt.jj.requestFocus();
        inimigo.getMateria().setFeitaNoDia(true);
        inimigo.getMateria().setFeitaNaSemana(inimigo.getMateria().getFeitaNaSemana()+1);
        inimigo.getMateria().setContadorCargaFeita(inimigo.getMateria().getContadorCargaFeita()+30);
        if(inimigo.getMateria().getContadorCargaFeita() == inimigo.getMateria().getCargaHoraria()){
            inimigo.getMateria().setStatus(3);
           
           
        }
    }
    player = interfaceBatalha.danoAoPlayer(player, inimigo);
    labelVidaPlayer.setText(Integer.toString(player.getHpAtual()));
    if(player.getHpAtual() <= 0){
        ProjetoIntegrado.sound.stopMidi();
        ProjetoIntegrado.sound.playGameOver();
        this.setVisible(false);
        ProjetoIntegrado.pgo.setVisible(true);
    }
    }else {
        jLabel4.setText("Nao foi nada efetivo!");
        player = interfaceBatalha.danoAoPlayer(player, inimigo);
        labelVidaPlayer.setText(Integer.toString(player.getHpAtual()));
        if(player.getHpAtual() <= 0){
        ProjetoIntegrado.sound.stopMidi();
        ProjetoIntegrado.sound.playGameOver();
        this.setVisible(false);
        ProjetoIntegrado.pgo.setVisible(true);
    }
    }
}//GEN-LAST:event_labelAtaqueAdmPlayerMouseClicked

private void labelAtaqueHumPlayerMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_labelAtaqueHumPlayerMouseClicked
    if(inimigo.materia.getTipo().equals("Humanas")){
        int i = (int)(Math.random()*player.frasesBatalhaHum.size());
        jLabel4.setText(player.frasesBatalhaHum.get(i));
    
    inimigo = interfaceBatalha.danoAoInimigoHum(player, inimigo);
    labelVidaInimigo.setText(Integer.toString(inimigo.getHp()));
    /*IMPLEMENTAR NA CLASSE DESENHATELA METODO DE ATUALIZAR DADOS DO PLAYER
    if(inimigo.getHp() == 0){
     * DesenhaTela.atualizaDadosPlayer(player)
     * this.dispose();
     * }
     */
    if(inimigo.getHp() <= 0){
    //    acordaThread();
        ProjetoIntegrado.sound.stopMidi();
        inimigo.setHp(100);
        player.setSkillHum(player.getSkillHum()+3);
        ProjetoIntegrado.pld.setSkillHum(player.getSkillHum());
        Flag.andar1BlocoE = false;
         Flag.andar2BlocoE = false;
        Flag.andar3BlocoE = false;
        Flag.playSoundOnce = true;
        this.setVisible(false);
        dt.jj.setVisible(true);
        dt.jj.requestFocus();
        inimigo.getMateria().setFeitaNoDia(true);
        inimigo.getMateria().setFeitaNaSemana(inimigo.getMateria().getFeitaNaSemana()+1);
        inimigo.getMateria().setContadorCargaFeita(inimigo.getMateria().getContadorCargaFeita()+30);
        if(inimigo.getMateria().getContadorCargaFeita() == inimigo.getMateria().getCargaHoraria()){
            inimigo.getMateria().setStatus(3);
            
        }
    }
    player = interfaceBatalha.danoAoPlayer(player, inimigo);
    labelVidaPlayer.setText(Integer.toString(player.getHpAtual()));
    if(player.getHpAtual() <= 0){
        ProjetoIntegrado.sound.stopMidi();
        ProjetoIntegrado.sound.playGameOver();
        this.setVisible(false);
        ProjetoIntegrado.pgo.setVisible(true);
    }
    }else{
        jLabel4.setText("Nao foi nada efetivo!");
        player = interfaceBatalha.danoAoPlayer(player, inimigo);
        labelVidaPlayer.setText(Integer.toString(player.getHpAtual()));
        if(player.getHpAtual() <= 0){
        ProjetoIntegrado.sound.stopMidi();
        ProjetoIntegrado.sound.playGameOver();
        this.setVisible(false);
        ProjetoIntegrado.pgo.setVisible(true);
    }
    }
}//GEN-LAST:event_labelAtaqueHumPlayerMouseClicked

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel labelAtaqueAdmPlayer;
    private javax.swing.JLabel labelAtaqueHumPlayer;
    private javax.swing.JLabel labelAtaqueMatPlayer;
    private javax.swing.JLabel labelAtaqueProgPlayer;
    private javax.swing.JLabel labelVidaInimigo;
    private javax.swing.JLabel labelVidaPlayer;
    private javax.swing.JPanel painelVidaInimigo;
    private javax.swing.JPanel painelVidaPlayer;
    // End of variables declaration//GEN-END:variables
}
